package main

import (
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
)

func main() {
	const (
		a = iota //0
		b        //1
		c        //2
		d = "ha" //独立值，iota += 1
		e        //"ha"   iota += 1
		f = 100  //iota +=1
		g        //100  iota +=1
		h = iota //7,恢复计数
		i        //8
	)
	fmt.Println(a, b, c, d, e, f, g, h, i)

	dataByte()

	get()

}

const (
	b = 1 << (10 * iota)
	kb
	mb
	gb
	tb
	pb
)

func dataByte() {
	fmt.Println("b=", b)
	fmt.Println("kb=", kb)
	fmt.Println("mb=", mb)
	fmt.Println("gb=", gb)
	fmt.Println("tb=", tb)
	fmt.Println("pb=", pb)
}

func get() {
	resp, err := http.Get("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=%E6%97%A0%E9%94%A1")
	if err != nil {
		// handle error
	}
	var reader io.ReadCloser
	if resp.Header.Get("Content-Encoding") == "gzip" {
		reader, err = gzip.NewReader(resp.Body)
		if err != nil {
			return
		}
	} else {
		reader = resp.Body
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(reader)

	if err != nil {
		// handle error
	}

	fmt.Println(string(body))
}
